﻿using System;
using System.Windows;
using System.Windows.Forms;
using Epitech.Krisk.Kinect.Sensor;
using Epitech.Krisk.Kinect.Sensor.Exception;
using MessageBox = System.Windows.MessageBox;

namespace Epitech.Krisk.Kinect.UI.Test
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private SensorManager _sensor;

        public MainWindow()
        {
            InitializeComponent();
            _sensor = SensorManager.Instance;
            DataContext = _sensor;
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //_sensor.StartSensorAction(SensorManager.StartAction.Swipe);
                //_sensor.StartSensorAction(SensorManager.StartAction.Navigation);
                //_sensor.StartSensorAction(SensorManager.StartAction.PausePosture);
                _sensor.StartSensorAction(SensorManager.StartAction.Cursor);
                Screen.Visibility = _sensor.NobodyInFrontOfScreen ? Visibility.Visible : Visibility.Collapsed;
                _sensor.PeopleDetector += (o, args) => { Screen.Text = args.Message; };
                _sensor.Navigation.SelectionEvent += (o, args) => { Navigation.Text = args.Position.ToString(); };
                _sensor.LSwipe.OnSwipeToRight += (o, args) => { SwipeGauche.Text = "SwipeToRight"; };
                _sensor.RSwipe.OnSwipeToLeft += (o, args) => { SwipeDroit.Text = "SwipeToLeft"; };
                _sensor.PausePosture.PauseActivated += (o, args) => Dispatcher.Invoke(new Action(DispatcherResync));
            }
            catch (KinectException ex)
            {
                MessageBox.Show(ex.ErrorMessage);
            }
        }

        private void DispatcherResync()
        {
            Pause.Text = "Pause";
        }

        private void WindowClosed(object sender, EventArgs e)
        {
            _sensor.UnInitialize();
        }
    }
}
